package com.GPSCoordinates;


import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;
import android.app.Activity;
import android.content.Context;
import android.view.Menu;
import android.widget.TextView;
import com.GPSCoordinates.R;

public class Android_Activity extends Activity implements 
		LocationListener {

	private LocationManager lm;
	

	private TextView latitude;
	private TextView longitude;
	

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main);

		// Find TextView by ID
		latitude = (TextView) findViewById(R.id.textLatitude);
		longitude = (TextView) findViewById(R.id.textLongitude);
		
		// Set up Location Manager
		lm = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
		
		// Set up GPS refresh time and minimum distance
		lm.requestLocationUpdates(LocationManager.GPS_PROVIDER, 0, 0, this);
		// Set up TextViews
		latitude.setText("waiting on latitude...");
		longitude.setText("waiting on longitude...");
		
		double startLatitude=30.21126769, startLongitude=-92.0287537, endLatitude=30.4122356, endLongitude=-92.1275972; 
		float[] navData = new float[3];
	    Location.distanceBetween(startLatitude, startLongitude, endLatitude, endLongitude, navData);
	    longitude.setText("D: "+ navData[0] + " SB: " + navData[1] + " EB: "+ navData[2]);
	    
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.android_, menu);
		return true;
	}

	@Override
	public void onLocationChanged(Location arg0) {
		//When location has changed trigger to get new latitude and longitude
		//Print new latitude and longitude
		
		latitude.setText("lat= " + arg0.getLatitude());
		// longitude.setText("lon= " + arg0.getLongitude());
		
	}

	@Override
	public void onProviderDisabled(String arg0) {
	}

	@Override
	public void onProviderEnabled(String arg0) {
	}

	@Override
	public void onStatusChanged(String arg0, int arg1, Bundle arg2) {
	}

}
